<include file="Common/header" />
<title>会员录入</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
</head>
<body>
<div class="pd-20">
	<div class="panel panel-primary">
		<div class="panel-header">基本信息</div> 
		<table class="table table-border table-bordered table-striped">
            <tr>
               	<td style="background-color: #f9f9f9;text-align: right">小区名称：</td>
                <td style="background-color: white">
					<input type="hidden" name="villageid" id="villageid" value="{$shopinfo['villageid']}" />
					<input type="text" name="title" id="title" class="input-text radius" value="{$shopinfo['title']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">所属分店：</td>
                <td style="background-color: white">
					<span class="select-box radius" style="width: 130px;">
						<select class="select" size="1" name="shop_id" id="shop_id">
							<?php foreach($shoplist as $spl){ ?>
							<option value="{$spl['shop_id']}" {$shopinfo['shop_id'] == $spl['shop_id'] ? 'selected' : ''}>{$spl['title']}</option>
							<?php } ?>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">区间单价：</td>
                <td style="background-color: white;">
					<input type="text" name="price" id="price" class="input-text radius" value="{$shopinfo['price']}" />
                </td>
            </tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">地区选择：</td>
                <td style="background-color: white" colspan="3">
					<span class="select-box radius" style="width: 130px;">
						<select class="select" size="1" name="region_cid" id="region_cid">
							<option value="0">重庆</option>
							<option value="1">四川</option>
						</select>
					</span>
					<span class="select-box radius" style="width: 130px;">
						<select class="select" size="1" name="region_cid" id="region_cid">
							<option value="0">重庆市</option>
							<option value="1">成都市</option>
						</select>
					</span>
					<span class="select-box radius" style="width: 130px;">
						<select class="select" size="1" name="region_cid" id="region_cid">
							<option value="0">渝北区</option>
							<option value="1">江北区</option>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">小区地址：</td>
                <td style="background-color: white;">
					<input type="text" name="address" id="address" class="input-text radius" value="{$shopinfo['address']}" />
                </td>
			</tr>
			<tr>
				<td width="150" class="text-r">封面图：</td>
				<td colspan="5">
					<form action="" method="post" class="form form-horizontal" id="uploadform" enctype="multipart/form-data">
						<span class="btn-upload"> 
							<a href="javascript:void();" class="btn btn-primary radius uploadBtn">
								<i class="Hui-iconfont"></i> 浏览文件
							</a>
							<input type="file" multiple="" name="file[]" class="input-file" onchange="uploadImages();">
						</span>
					</form>
					<input type="hidden" name="images" id="images" value="{$shopinfo['images']}" />
					<div id="imgshow" style="display: <?php echo empty($shopinfo['images']) ? 'none' : 'block'; ?>;">
						<hr />
						<img src="__PUBLIC__/upload/{$shopinfo['images']}" style="width: 100px; height: 100px;"/>
					</div>
				</td>
			</tr>
			<tr>
				<td width="150" class="text-r">小区描述：</td>
				<td colspan="5">
					<textarea id="editor" type="text/plain" style="width: 720px; height: 200px;"><?php echo html_entity_decode($shopinfo['desc']); ?></textarea>
				</td>
			</tr>
		</table>
	</div>

	<div class="mt-5 mb-5 text-c">
		<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save">
			<i class="icon-ok"></i> 确  定
		</button>
	</div>
</div>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.min.js"> </script>
<script>
	function uploadImages(){
		var load = layer.load(2);
		$("#uploadform").ajaxSubmit({
			type:'post',
			url:'../index/upload.html',
			success:function(data){
				layer.close(load);
				var data = JSON.parse(data);
				if(data.errCode/1 > 0){
					layer.msg('上传成功', {icon:1, time: 2000});
					$("#images").val(data.errMsg);
					$("#imgshow").show();
					$("#imgshow img").attr('src', "__PUBLIC__/upload/"+ data.errMsg);
				}else{
					layer.msg(data.errMsg, {icon:2, time: 2000});
				}
			},
			error:function(XmlHttpRequest,textStatus,errorThrown){
				
			}
		});
	}

	$(document).ready(function(){
		var ue = UE.getEditor('editor', {
			allHtmlEnabled: false,//提交到后台的数据是否包含整个html字符串
			autoHeightEnabled: false,
			autoFloatEnabled: true,
			allowDivTransToP: false//阻止div标签自动转换为p标签
		});
		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			var data = {};
			if($("#title").val() == ""){
				layer.msg("请输入分店名称", {icon: 2, time:2000});
				return false;
			}else{
				data.title = $("#title").val();
			}

			data.shop_id = $("#shop_id").val();
			var price = $("#price").val();
			if(price.length > 10){
				layer.msg('请输入分店推荐价格', {icon: 5, time: 2000});
				return false;
			}else{
				data.price = price;
			}

			var address = $("#address").val();
			if(address.length <= 0 || address.length > 100){
				layer.msg('请正确输入分店地址', {icon: 5, time: 2000});
				return false;
			}else{
				data.address = address;
			}

			var images = $("#images").val();
			if(images.length <= 0){
				layer.msg('请上传封面图片', {icon: 5, time: 2000});
				return false;
			}else{
				data.images = images;
			}
			data.villageid = $("#villageid").val();
			data.desc = ue.getContent();
			var load = layer.load(2);
			$.post('villageadd.html', data, function(row){
				layer.close(load);
				if(row == 1){
					layer.msg('编辑成功', {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    	parent.layer.close(index);
					});
				}else{
					layer.msg('编辑失败', {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>